using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace WPCoco.Graphics
{
    public enum QuadDirtyComponent
    {
        None = 0,
        Color = 1,
        Position = 2,
        Texture = 4,
        All = 7
    }

    /// <summary>
    /// Store 4 Vertex for draw and quad, in class is used by the AtlasSprite for storing drawing sprites info
    /// </summary>
    public class AtlasQuad
    {
        public readonly VertexPositionColorTexture[] vertexs = new VertexPositionColorTexture[4];

        public static AtlasQuad Create(TextureFrame frame, RectangleF location, Color color, float depth)
        {
            AtlasQuad quad = new AtlasQuad();

            //Color Components
            quad.vertexs[0].Color = quad.vertexs[1].Color = quad.vertexs[2].Color = quad.vertexs[3].Color = color;

            // Position Components
            quad.vertexs[0].Position = new Vector3(location.X, location.Y, depth);
            quad.vertexs[1].Position = new Vector3(location.X + location.Width, location.Y, depth);
            quad.vertexs[2].Position = new Vector3(location.X + location.Width, location.Y + location.Height, depth);
            quad.vertexs[3].Position = new Vector3(location.X, location.Y + location.Height, depth);

            // Texture Components
            RectangleF normalized = frame.TextureRegionNormalized;
            quad.vertexs[0].TextureCoordinate = new Vector2(normalized.X, normalized.Y);
            quad.vertexs[1].TextureCoordinate = new Vector2(normalized.X + normalized.Width, normalized.Y);
            quad.vertexs[2].TextureCoordinate = new Vector2(normalized.X + normalized.Width, normalized.Y + normalized.Height);
            quad.vertexs[3].TextureCoordinate = new Vector2(normalized.X, normalized.Y + normalized.Height);
            return quad;
        }
    }
}
